import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        userInfo: JSON.parse(localStorage.getItem("userInfo")),
        token: localStorage.getItem("token"),
        routers: JSON.parse(localStorage.getItem("routers")),
        controllerBtn: false,
        active: localStorage.getItem("active"),
        tagVal: JSON.parse(localStorage.getItem("tagVal"))
    },
    getters: {
        getUser: state => {
            return state.userInfo
        },
        getToken: state => {
            return state.token
        },
        getRouters: state => {
            return state.routers
        },
        getControllerBtn: state => {
            return state.controllerBtn
        },
        getActive: state => {
            return state.active
        },
        getTagVal: state => {
            return state.tagVal
        }
    },
    mutations: {
        SET_USERINFO: (state, userInfo) => {
            state.userInfo = userInfo
            localStorage.setItem("userInfo", JSON.stringify(userInfo))
        },
        SET_TOKEN: (state, token) => {
            state.token = token
            localStorage.setItem("token", token)
        },
        SET_ROUTERS: (state, routers) => {
            state.routers = routers
            localStorage.setItem("routers", JSON.stringify(routers))
        },
        REMOVE_INFO: (state) => {
            state.userInfo = {}
            state.token = ''
            state.routers = ''

            localStorage.setItem("userInfo", JSON.stringify(''))
            localStorage.setItem("token", '')
            localStorage.setItem("routers", '')
            localStorage.setItem("active", JSON.stringify(''))
            localStorage.setItem("tagVal", JSON.stringify(''))
            localStorage.clear()

        },
        SET_CONTROLLERBTN: (state) => {
            state.controllerBtn = !state.controllerBtn
        },
        SET_ACTIVE: (state, routers) => {
            state.active = routers
            localStorage.setItem("active", routers)
        },
        SET_TAGVAL:(state,routers)=>{
            state.tagVal = routers
            localStorage.setItem("tagVal", JSON.stringify(routers))
        }
    },
    actions: {},
    modules: {}
})
